<?php

/**
 * 2021/3/23
 * Created by breeze
 * User: breeze
 */
namespace app\admin\business;
class newsBus
{
    public $newsMode = null;
    public function __construct()
    {
        $this->newsMode = new \app\common\model\News();
    }

    public function addNews($data){
        $sessionData = session(config("admin.session_admin"));
        $auto = [
            "auto"=>$sessionData['name']
        ];
        $data = array_merge($auto,$data);
        $result = $this->newsMode->addNews($data);
        return $result;
    }
    public function getNewsList($current_page,$num){
        $result = $this->newsMode->getList($current_page,$num);
        if(empty($result)){
            throw new \think\Exception('未查询到数据');
        }
        return $result;
    }
    public function getNewsDetail($id){
        $result = $this->newsMode->getDetailById($id);
        if(empty($result)){
            throw new \think\Exception('未查到该内容');
        }
        return $result;
    }
    public function updateNews($data){
        $id = $data['id'];

        $data = array_diff($data,[$id]);

        $result = $this->newsMode->updateNews($id,$data);
        if(empty($result)){
            throw new \think\Exception('内容未更改，请检查数据');
        }
        return $result;
    }

    public function changeStatus($data){
        $id = $data['id'];
        $data = array_diff($data,[$id]);
        $result = $this->newsMode->updateNews($id,$data);
        if(empty($result)){
            throw new \think\Exception('状态未更改');
        }
        return $result;
    }
    public function removeNews($id){
        $result = $this->newsMode->removeNews($id);
        if(empty($result)){
            throw new \think\Exception("未查到删除的信息或者改信息已经删除");
        }
        return $result;
    }
}